package com.infy.olt.action;

import com.infy.olt.dto.LoginDtl;
import com.infy.olt.service.TableConfigurationService;
import com.opensymphony.xwork2.ActionSupport;

public class TableConfigurationAction extends ActionSupport {
	
	private TableConfigurationService tableConfigurationService;
	
	/**
	 * @return the tableConfigurationService
	 */
	public TableConfigurationService getTableConfigurationService() {
		return tableConfigurationService;
	}

	/**
	 * @param tableConfigurationService the tableConfigurationService to set
	 */
	public void setTableConfigurationService(
			TableConfigurationService tableConfigurationService) {
		this.tableConfigurationService = tableConfigurationService;
	}

	private String username = null;

	private String password = null;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getLogin() {
		System.out.println("Validating login");
		String userName = getUsername().toUpperCase();
		LoginDtl loginDtl = tableConfigurationService.getLoginDetails(userName);
		String result = null;
		if (loginDtl == null) {
			//addActionError("Invalid user name! Please try again!");
			result = ERROR;
		}else if (loginDtl.getPassword() != null && !loginDtl.getPassword().equals(getPassword())) {
			//addActionError("Invalid password! Please try again!");
			result = ERROR;
		}else if(loginDtl.getPassword().equals(getPassword())){
			result = SUCCESS;
		}
		return result;
	}
}